Ext.define('DealWithYuXuanView', {
	extend : 'Ext.panel.Panel',
	id : 'DealWithYuXuanView',
	title : '教师确认预选',
	region : 'center',
	layout : 'border',
	iconCls: 'menu-cusLinkman',

	initComponent : function() {		
		this.searchPanel = new KE.SearchPanel({
					region : 'north',
					items : [{
								text : '题目'
							}, {
								width : 120,
								name : 'Q_LIKES_name',
								xtype : 'textfield'								
							}, {
								xtype : 'button',
								text : '查询',
								scope : this,
								iconCls : 'btn-search',
								handler : this.search
							}, {
								xtype : 'button',
								text : '清空',
								scope : this,
								iconCls : 'reset',
								handler : this.reset
							}]
				});

		this.topbar = new Ext.Toolbar({
			items : [{
						iconCls : 'btn-doc',
						text : '导出审报表',
						xtype : 'button',
						scope : this,
						handler : this.exportWord
					}]
		});

		this.gridPanel = new KE.GridPanel({
			region : 'center',
			tbar : this.topbar,
			id : 'DealWithYuXuanGrid',
			url : __ctxPath + "/byxt/listMyTongGuoSubject.do",
			fields : ['oid', 'name', 'status', {
								name : 'teacher.fullname',
								mapping : 'teacher.fullname'
							}, {
								name : 'fromType.itemValue',
								mapping : 'fromType.itemValue'
							}, {
								name : 'type.itemValue',
								mapping : 'type.itemValue'
							},{
								name : 'student.fullname',
								mapping : 'student.fullname'
							}],
			columns : [{
						header : 'ID',
						dataIndex : 'oid',
						hidden : true
					}, {
						header : '题目',
						dataIndex : 'name',
						flex: 2
					}, {
						header : '指导教师',
						dataIndex : 'teacher.fullname'
					}, {
						header : '题目来源',
						dataIndex : 'fromType.itemValue'
					}, {
						header : '题目类型',
						dataIndex : 'type.itemValue'
					},{
						header : '当前预选人数',
						dataIndex : 'xscnt',
						renderer: function(v) {
							if(v== null) return '0';
							return v;
						}
					},{
						header : '最终分配学生',
						dataIndex : 'student.fullname',
						renderer: function(v) { 
							if(v== null) return '<span class="bg-warning">（未分配）</span>';
							return '<span class="bg-success">' + v + '</span>';
						}
					}, {
						text : '预选学生确认',
						xtype : 'actioncolumn',
						items : [{
									iconCls : 'btn-user-sel',
									tooltip : '处理预选',
									scope : this,
									handler :function(grid, rowIndex, colIndex) {
										var rec = grid.getStore().getAt(rowIndex);
										this.dealWithYuxuanFun(rec);
									} 					
							}]
					}]
		});

		this.items = [this.searchPanel, this.gridPanel];
		this.callParent();
		this.gridPanel.on('rowdblclick', this.rowClick);
	},
	// 重置查询表单
	reset : function() {
		this.searchPanel.getForm().reset();
		Ext.each(this.searchPanel.query('combo'), function(c) {
			c.setValue('');
			c.setRawValue('');
		});
	},
	// 按条件搜索
	search : function() {
		$search({
			searchPanel : this.searchPanel,
			gridPanel : this.gridPanel
		});
	},
	// GridPanel行点击处理事件
	rowClick : function(grid, rec) {
			new SubjectCheckForm({
				sid : rec.data.oid
			}).show();
		
	},
	// 流转信息
	viewRs: function(record) {
		new WndShow({
			height : 450,
		    width : 850,
			title: '流转信息',
			url: __ctxPath + '/byxt/showOpinionSubject.do?oid=' + record.data.oid
		}).show();
	},
	
	//处理预选
	dealWithYuxuanFun:function(rec){
		var a = this.gridPanel;
		if(rec.data.xscnt==0){
			 Ext.Msg.alert('操作信息', '此题还未有学生选择');
			 return;
		}
		if(rec.data.status==5){
			 Ext.Msg.alert('操作信息', '此题已经分配完毕');
			 return;
		}
		// 学生选择器
		AppUserSelector.getView2(
			function(ids) {
				if(ids!=null) {
					$postAjax({
						 url: __ctxPath + '/byxt/saveStudentSubject.do',
						 params: {
								ids: ids,
								oid: rec.data.oid
						},
						grid : a
					});
				}
			}, true, 3, rec.data.oid).show();		
	}

});
